package com.yanqu.road.server.manger.player.task;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.tradewar.UserTradeWarInfo;
import com.yanqu.road.logic.bussiness.player.UserTradeWarBussiness;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.TradeWarMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.executor.GeneralTask;

public class NotifyBeKillPatronsCountTask extends GeneralTask {

    private long userId;
    private int killPatronsCount;

    public NotifyBeKillPatronsCountTask(long userId, int killPatronsCount) {
        this.userId = userId;
        this.killPatronsCount = killPatronsCount;
    }

    @Override
    public void doRun() {
        UserTradeWarInfo enemyTradeWarInfo = TradeWarMgr.getUserTradeWarInfo(userId);
        synchronized (enemyTradeWarInfo) {
            enemyTradeWarInfo.setTotalBeKillPatronsCount(enemyTradeWarInfo.getTotalBeKillPatronsCount() + killPatronsCount);
        }
        GamePlayer enemyPlayer = GamePlayerMgr.getOnlinePlayer(userId);
        //成就、任务
        if (null != enemyPlayer) {
            enemyPlayer.notifyListener(eGamePlayerEventType.TradeWarTotalBeKillPatronsCount.getValue(), enemyTradeWarInfo);
        } else {
            UserTradeWarBussiness.updateUserTradeWarInfo(enemyTradeWarInfo);
        }
    }
}
